﻿@inject IOptionsSnapshot<SiteOptions> SiteOptions
@inject ITagService Service
@inject IDistributedCacheHelper CacheHelper

@{
    const string cacheKey = "_TagCloudsPartial";

    async Task<List<TagBrief>?> GetTagFromDb()
    {
        return await Service.GetTagsAsync(int.MaxValue);
    }

    var tags = await CacheHelper.GetOrCreateAsync(cacheKey,
        async e => await GetTagFromDb());
}

@if (tags is {Count:>0})
{
    <div class="whitebg cloud">
        <h2 class="side-title">标签云</h2>
        <ul>
            @foreach (var tag in tags.RandomItems(20))
            {
                <a href="/tag/@tag.Name" target="_blank">@tag.Name (@tag.BlogCount)</a>
            }
        </ul>
    </div>
}